<template>
	<view class="form-container">
		<nt-order-detail :orderInfo="commonForm.orderInfo"></nt-order-detail>
		<nt-card label="师傅备注">
			<view class="form-item vertical">
				<view class="form-item__label">师傅备注：</view>
				<view class="form-item__content">
					<u--textarea v-model="formData.remarks" maxlength="-1" :confirmType="null"></u--textarea>
				</view>
			</view>
			<view class="form-item vertical">
				<view class="form-item__label">上传图片：</view>
				<view class="form-item__content">
					<nt-upload @success="formData.images = $event"></nt-upload>
				</view>
			</view>
			<nt-button text="提交" @tap="submit"></nt-button>
		</nt-card>
	</view>
</template>

<script>
import { addWorkerRemarks } from "@/api"
export default {
	data(){
		return {
			formData: {
				remarks: "",
				images: [],
				remarks_id: ""
			},
			loading: false
		}
	},
	inject: ["commonForm"],
	methods: {
		submit(){
			const { remarks, images, remarks_id } = this.formData
			if(!this.formData.remarks) return this.toast("备注内容不能为空")
			if(this.loading) return;
			this.loading = true
			addWorkerRemarks({
				realorder_id: this.commonForm.options.id,
				remarks,
				images: images.map(item => item.url),
				remarks_id
			}).then(res => {
				const { code, msg } = res;
				if(code !== 1) return this.toast(msg)
				this.toast("备注成功")
				setTimeout(() => this.back(), 1000)
			}).finally(() => {
				this.loading = false
			})
		}
	}
}
</script>
<style scoped lang="scss">
@import "./style.scss";
</style>